package com.hzau.tourist_service_sys.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.hzau.tourist_service_sys.dao.ScenicSpot.ScenicSpotDao;
import com.hzau.tourist_service_sys.dao.Weather.WayDao;
import com.hzau.tourist_service_sys.dao.Weather.WeatherDao;
import com.hzau.tourist_service_sys.pojo.ScenicSpot.ScenicSpot;
import com.hzau.tourist_service_sys.pojo.Weather.Way;
import com.hzau.tourist_service_sys.result.Result;
import com.hzau.tourist_service_sys.service.WeatherService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
@Transactional
@Service
public class WeatherServiceImpl implements WeatherService {
    int pagesize=10;
    @Autowired
    WeatherDao weatherDao;
    @Autowired
    WayDao wayDao;
    @Autowired
    ScenicSpotDao scenicSpotDao;


    @Override
    public Result selectAllWeather(int pagenum) {
        IPage page=new Page(pagenum,pagesize);
         weatherDao.selectPage(page, null);
        return Result.success(page);

    }

    @Override
    public Result selectWeatherDetail(int spotId) {
        return Result.success(weatherDao.selectById(spotId));
    }

    @Override
    public Result queryWeather(ScenicSpot sc) {
//        IPage page=new Page(sc.getPagenum(),pagesize);
//        LambdaQueryWrapper<ScenicSpot> lqw=new LambdaQueryWrapper<>();
//        lqw.eq(sc.getSpotName()!=null,ScenicSpot::getSpotName,sc.getSpotName());
//        ScenicSpot scenicSpot = scenicSpotDao.selectOne(lqw);
        return Result.success(weatherDao.selectById(sc.getSpotId()));
    }

    @Override
    public Result selectAllConditons(int pagenum) {
        IPage page=new Page(pagenum,pagesize);
        wayDao.selectPage(page, null);


        return Result.success(page.getRecords());
    }

    @Override
    public Result queryCondtions(Way way) {
        if (way.getPagenum()==null){
            way.setPagenum(1);
        }
        IPage page=new Page(way.getPagenum(),pagesize);
        LambdaQueryWrapper<Way> lqw=new LambdaQueryWrapper<>();
        lqw.like(way.getWayName()!=null,Way::getWayName,way.getWayName());
        lqw.like(way.getLocation()!=null,Way::getLocation,way.getLocation());
        List<Way> ways = wayDao.selectPage(page,lqw).getRecords();
        return Result.success(ways);
    }
}
